﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation;
using Microhard.WarehouseInsp.Buz.Models;
using Microhard.WarehouseInsp.Buz.Msg;
using Microhard.WarehouseInsp.Buz.Interfaces;
using Microhard.Core;
using FluentValidation.Results;

namespace Microhard.WarehouseInsp.Buz.Validator
{

    public class RiskRecordsModelValidator : AbstractValidator<RiskRecordsModel>
    {
        public RiskRecordsModelValidator()
        {
            RuleSet("Insert", () =>
            {
                RuleFor(u => u.RiskReason).NotEmpty().WithMessage(RiskRecordsMsg.NeedRiskReason).When(r => r.OperationStatus == Core.DBUtility.OperationStatus.Add);
                //RuleFor(u => u.Exet).NotEmpty().WithMessage(RiskRecordsMsg.NeedExet).When(r => r.OperationStatus == Core.DBUtility.OperationStatus.Add);

                Custom(u =>
                {
                    if (Guid.Empty == u.ProjectID)
                    {
                        return new ValidationFailure("ProjectID", RiskRecordsMsg.NeedProjectID);
                    }
                    return null;
                });
            });

            RuleSet("Insert", () =>
            {
                RuleFor(u => u.RiskReason).NotEmpty().WithMessage(RiskRecordsMsg.NeedRiskReason);
                //RuleFor(u => u.Exet).NotEmpty().WithMessage(RiskRecordsMsg.NeedExet);
            });
        }
    }
}

